<!DOCTYPE html>
<html>
<head>
    <meta content="text/html" charset="UTF-8">
    <title>微信管理平台</title>
    <link rel="stylesheet" type="text/css" href="css/themes/default/easyui.css">
    <link rel="stylesheet" href="css/themes/icon.css"/>
    <link rel="stylesheet" href="css/themes/color.css"/>
    <link rel="stylesheet" type="text/css" href="css/mycss.css"/>
    <link rel="stylesheet" type="text/css" href="css/themes/portal.css"/>
    <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
</head>
<body>
<div class="easyui-layout" fit="true">
    <div data-options="region:'center',split:true,border:false">
        <table id="weixin_user_datagird"></table>
    </div>
</div>

<div style="display: none">
</div>
<script type="text/javascript">
    var $=$||{};
    var $weixin_user_datagird=$('#weixin_user_datagird');
    $weixin_user_datagird.datagrid({
        url:'user/list.json',
        saveUrl:'user/api?method=add',
        editUrl:'user/api?method=update',
        delUrl:'user/api?method=del',
        columns: [
            [
                {field:'ck',checkbox:true},
                {field: 'id', title: 'UserId'},
                {field: 'username', title: '用户名',editor:{type:'textbox',options:{required:true}}},
                {field: 'groupid', title: '用户组',width:180,
                    formatter:function(value,row){
                        return row.groupname;
                    },
                    editor:{
                        type:'combobox',
                        options:{
                            valueField:'id',
                            textField:'groupname',
                            method:'get',
                            url:'usergroup/list.json',
                            required:true,
                            loadFilter:function(data){
                                console.log(data);
                                return data.rows;
                            }

                        }
                    }
                },
                {field: 'creattime', title: '创建时间', width: 180,formatter:function(value){
                	return new Date(value).toLocaleString();
                }}
                /*{field: 'btn', title: '操作', formatter: function () {
                 return btn2;
                 }}*/
            ]
        ],
        onBeforeEdit:function(rowIndex){
            var a = $weixin_user_datagird.datagrid('options');
            console.log('开始编辑:'+rowIndex);
            a.edititem.push(rowIndex);
        },
        onDblClickRow:function(rowIndex){
            $weixin_user_datagird.datagrid('beginEdit',rowIndex);
        },
        toolbar:[
            {
                iconCls:'icon-add',
                text:'添加',
                handler:function(){
                    $weixin_user_datagird.datagrid('addRow',{
                                "username":"",
                                "creattime":new Date().getTime()
                    });
                }
            },
            {
                iconCls:'icon-save',
                text:'接受改变',
                handler:function(){
                	$weixin_user_datagird.datagrid('RecChange',{groupid:'groupname'});
                }
            },
            {
                iconCls:'icon-save',
                text:'保存',
                handler:function(){
                	$weixin_user_datagird.datagrid('SaveData');
                }
            },
            {
                iconCls:'icon-cancel',
                text:'取消更改',
                handler:function(){
                    $weixin_user_datagird.datagrid('CancelEdit');
                }
            },
            {
                iconCls:'icon-remove',
                text:'删除',
                handler:function(){
                	$weixin_user_datagird.datagrid('DelRows');

                }
            }
        ]
    });
</script>
</body>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/jquery.portal.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="js/jquery.edatagrid.js"></script>
</html>